/* GUI CONVERTED from apvoiqb.p (converter v1.76) Tue Apr 22 19:39:46 2003 */
/* apvoiqb.p - AP VOUCHER INQUIRY - VOUCHER DISPLAY SUB-PROGRAM             */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.             */
/* $Revision: 1.14.2.15 $                                                         */
/*V8:ConvertMode=Report                                                     */
/* Created to replace apvoiq.i                                              */
/* REVISION: 7.4           CREATED: 06/01/95   BY: jzw *G0P2*               */
/* REVISION: 8.5     LAST MODIFIED: 03/22/96   BY: *J0CV* Brandy J Ewing    */
/* REVISION: 8.6     LAST MODIFIED: 10/10/96   BY: svs *K007*               */
/* REVISION: 8.6     LAST MODIFIED: 10/08/97   BY: ckm *K0MW*               */
/* REVISION: 8.6E    LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane         */
/* REVISION: 8.6E    LAST MODIFIED: 04/08/98   BY: *L00M*  DS               */
/* REVISION: 8.6E    LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan        */
/* REVISION: 8.6E    LAST MODIFIED: 06/02/98   BY: *L03L* Brenda Milton     */
/* REVISION: 8.6E    LAST MODIFIED: 08/28/98   BY: *L07P* GYK               */
/* REVISION: 9.0     LAST MODIFIED: 03/10/99   BY: *M0B3* Michael Amaladhas */
/* REVISION: 9.0     LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan        */
/* REVISION: 9.1     LAST MODIFIED: 10/01/99   BY: *N014* Murali Ayyagari   */
/* REVISION: 9.1     LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1     LAST MODIFIED: 08/11/00   BY: *N0KK* jyn               */
/* REVISION: 9.1     LAST MODIFIED: 08/25/00   BY: *M0RS* Shilpa Athalye    */
/* REVISION: 9.1     LAST MODIFIED: 10/19/00   BY: *N0W0* BalbeerS Rajput  */
/* REVISION: 9.1      LAST MODIFIED: 29 JUN 2001 BY: *N0ZX* Ed van de Gevel */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.14.2.8.1.3 BY: Ed van de Gevel    DATE: 11/05/01  ECO: *N15M*  */
/* Revision: 1.14.2.10    BY: Lena Lim           DATE: 06/13/02  ECO: *P089*  */
/* Revision: 1.14.2.11    BY: Mamata Samant      DATE: 06/19/02  ECO: *N1K9*  */
/* Revision: 1.14.2.12    BY: Ed van de Gevel    DATE: 07/04/02  ECO: *P0B4*  */
/* Revision: 1.14.2.13    BY: Hareesh V.         DATE: 06/21/02  ECO: *N1HY*  */
/* Revision: 1.14.2.14    BY: Ed van de Gevel    DATE: 12/03/02  ECO: *N1ZQ* */
/* $Revision: 1.14.2.15 $  BY: Orawan S.       DATE: 04/22/03  ECO: *P0QB* */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdeclre.i}
{cxcustom.i "APVOIQB.P"}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE apvoiqb_p_1 "ERS"
/* MaxLen: Comment: */

&SCOPED-DEFINE apvoiqb_p_2 "Amt Open"
/* MaxLen: Comment: */

&SCOPED-DEFINE apvoiqb_p_3 "Exch Rate"
/* MaxLen: Comment: */

{&APVOIQB-P-TAG1}
/* ********** End Translatable Strings Definitions ********* */

define input parameter ap_recid  as recid.
define input parameter vo_recid  as recid.
define input parameter vpo_recid as recid.
define input parameter open_only like mfc_logical.
define input parameter base_rpt  like ap_curr.
define input parameter aptype    like ap_type.
define input-output parameter undo_all like mfc_logical no-undo.

define variable base_amt         like ap_amt no-undo.
define variable base_applied     like vo_applied no-undo.
define variable base_hold_amt    like vo_hold_amt no-undo.
define variable disp_curr        like ap_curr format "x(1)" no-undo.
define variable amt_open         like ap_amt
   label {&apvoiqb_p_2} no-undo.
define variable base_damt        like vod_amt no-undo.
define variable base_camt        like ckd_amt no-undo.
define variable base_disc        like ckd_disc no-undo.
define variable vopo             like vpo_po no-undo.
define shared variable mc-rpt-curr like ap_curr no-undo.
{&APVOIQB-P-TAG20}
define buffer apmstr for ap_mstr.

{&APVOIQB-P-TAG23}
{etrpvar.i }
{etvar.i   }

undo_all = yes.
do on endkey undo, return:

   find ap_mstr where recid(ap_mstr) = ap_recid
   no-lock.
   find vo_mstr where recid(vo_mstr) = vo_recid
   no-lock.
   if vpo_recid <> ? then
   find vpo_det where recid(vpo_det) = vpo_recid
   no-lock.
   find first gl_ctrl
   no-lock.

   assign
      vopo = if available vpo_det then vpo_po else ""
      base_amt = ap_amt
      base_applied = vo_applied
      base_hold_amt = vo_hold_amt
      disp_curr = "".
   {&APVOIQB-P-TAG2}
   if base_rpt = "" and ap_curr <> base_curr then do:
      {&APVOIQB-P-TAG3}

      assign
         base_amt = ap_base_amt
         base_applied = vo_base_applied
         base_hold_amt = vo_base_hold_amt
         disp_curr = getTermLabel("YES",1).
   end.

   {&APVOIQB-P-TAG4}
   if et_report_curr <> mc-rpt-curr then do:
      {&APVOIQB-P-TAG5}
      {gprunp.i "mcpl" "p" "mc-curr-conv"
         "(input mc-rpt-curr,
           input et_report_curr,
           input et_rate1,
           input et_rate2,
           input base_amt,
           input true,  /* ROUND */
           output base_amt,
           output mc-error-number)"}
      if mc-error-number <> 0 then do:
         {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
      end.
      {gprunp.i "mcpl" "p" "mc-curr-conv"
         "(input mc-rpt-curr,
           input et_report_curr,
           input et_rate1,
           input et_rate2,
           input base_applied,
           input true,  /* ROUND */
           output base_applied,
           output mc-error-number)"}
      if mc-error-number <> 0 then do:
         {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
      end.
      {gprunp.i "mcpl" "p" "mc-curr-conv"
         "(input mc-rpt-curr,
           input et_report_curr,
           input et_rate1,
           input et_rate2,
           input base_hold_amt,
           input true,  /* ROUND */
           output base_hold_amt,
           output mc-error-number)"}
      if mc-error-number <> 0 then do:
         {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
      end.
   end.  /* if et_report_curr <> mc-rpt-curr */

   amt_open = if vo_applied = ap_amt
      then
   0
   else base_amt - base_applied.

   {&APVOIQB-P-TAG24}
   if (not open_only or base_amt - base_applied <> 0) then do:

      {&APVOIQB-P-TAG25}
      if aptype = "RV" then do with frame b:
         {&APVOIQB-P-TAG6}
         /* SET EXTERNAL LABELS */
         setFrameLabels(frame b:handle).
         {&APVOIQB-P-TAG7}

         {&APVOIQB-P-TAG26}
         display
            ap_ref            colon 11 format "x(8)"
            vo_invoice        colon 35
            /*vo_type colon 60*/
            ap_date           colon 11
            vo_cr_terms       colon 35
            vo_type           colon 60
            /*base_amt colon 60*/
            ap_curr           colon 11
            disp_curr         no-label
            base_amt          colon 60
            ap_acct           colon 11
            ap_sub            no-label
            ap_cc             no-label
            vo_rcycle         colon 60
            (ap_ex_rate / ap_ex_rate2) @ ap_ex_rate
                              colon 11 label {&apvoiqb_p_3}
            ap_entity         colon 35
            vo_rnbr_cyc       colon 60
            ap_vend           colon 11
            vopo              colon 35
            vo_rstart         colon 60
            vo_confirmed      colon 11
            vo_conf_by        colon 35
            vo_rexpire        colon 60
            ap_ckfrm          colon 11
            {&COMMENT-START} format "x(1)" {&COMMENT-END}
            ap_batch          colon 35
            vo_rel_date       colon 60
         with frame b side-labels width 120 STREAM-IO /*GUI*/ .
         {&APVOIQB-P-TAG27}

      end. /* if aptype = "RV" */
      else if aptype = "VO" then do with frame c:
         {&APVOIQB-P-TAG8}
         /* SET EXTERNAL LABELS */
         setFrameLabels(frame c:handle).
         {&APVOIQB-P-TAG9}

         /*fdn*/ FIND FIRST vd_mstr NO-LOCK WHERE vd_addr = ap_vend NO-ERROR.

         {&APVOIQB-P-TAG28}
         display
            ap_ref         colon 11 format "x(8)"
            vo_invoice     colon 35
             /*fdn*/ vd_sort  WHEN (AVAILABLE vd_mstr) COLON 80
            /*vo_type colon 60*/
            ap_date        colon 11
            vo_cr_terms    colon 35
            vo_type        colon 60
            /*base_amt colon 60*/
            ap_effdate     colon 11
            base_amt       colon 60
            /*amt_open colon 60*/
            ap_acct        colon 11
            ap_sub         no-label
            ap_cc          no-label
            amt_open       colon 60
            (ap_ex_rate / ap_ex_rate2) @ ap_ex_rate
                           colon 11 label {&apvoiqb_p_3}
            ap_entity      colon 35
            ap_curr        colon 60
            disp_curr      no-label
            ap_vend        colon 11
            vopo           colon 35
            ap_batch       colon 60
            vo_confirmed   colon 11
            vo_conf_by     colon 35
            vo_rv_nbr      colon 60
            ap_ckfrm       colon 11
            {&COMMENT-START} format "x(1)" {&COMMENT-END}
            base_hold_amt  colon 35
            vo_is_ers      colon 60 label {&apvoiqb_p_1}
         with frame c side-labels width 120 STREAM-IO /*GUI*/ .
         {&APVOIQB-P-TAG29}
      end. /* else if aptype = "VO" */

      find vd_mstr where vd_addr = ap_vend no-lock no-error.
      if available vd_mstr then do:
         if vd_misc_cr and ap_remit <> "" then do:
            find ad_mstr where ad_addr = ap_remit no-lock no-error.
            if available ad_mstr then do with frame vohdr:
               /* SET EXTERNAL LABELS */
               setFrameLabels(frame vohdr:handle).
               display
                  skip
                  ad_name        colon 08
                  ad_line1       colon 08
                  ad_line2       colon 08
                  ad_state       colon 45
                  ad_zip
                  ad_format
                  ad_line3       colon 08
                  ad_county      colon 45
                  ad_city        colon 08
                  ad_country     colon 45
               with frame vohdr side-labels title color
                  normal (getFrameTitle("REMIT-TO",13)) width 120 STREAM-IO /*GUI*/ .
            end.
         end.
      end.

      for each vod_det where vod_ref = ap_ref
         no-lock with frame d width 120
            on endkey undo, return:
         /* SET EXTERNAL LABELS */
         setFrameLabels(frame d:handle).
         base_damt = vod_amt.
         {&APVOIQB-P-TAG10}
         if base_rpt = "" and base_curr <> ap_curr
         then do:
            {&APVOIQB-P-TAG11}

            /* CONVERT FROM FOREIGN TO BASE CURRENCY */
            {gprunp.i "mcpl" "p" "mc-curr-conv"
               "(input ap_curr,
                 input base_curr,
                 input ap_ex_rate,
                 input ap_ex_rate2,
                 input base_damt,
                 input true, /* ROUND */
                 output base_damt,
                 output mc-error-number)"}.
            if mc-error-number <> 0 then do:
               {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
            end.

         end.

         {&APVOIQB-P-TAG12}
         if et_report_curr <> mc-rpt-curr then do:
            {&APVOIQB-P-TAG13}
            {gprunp.i "mcpl" "p" "mc-curr-conv"
               "(input mc-rpt-curr,
                 input et_report_curr,
                 input et_rate1,
                 input et_rate2,
                 input base_damt,
                 input true,  /* ROUND */
                 output base_damt,
                 output mc-error-number)"}
            if mc-error-number <> 0 then do:
               {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
            end.
         end.  /* if et_report_curr <> mc-rpt-curr */

         /* DISPLAYING BASE AMOUNT FOR SYSTEM GENERATED vod_det */
         /* WHILE REPORTING IN BASE CURRENCY                    */
         if  vod_type       = "x"
         and et_report_curr = base_curr
         then
            base_damt = vod_base_amt.

         {&APVOIQB-P-TAG30}
         display
            vod_ln
            vod_acct
             vod_sub
             vod_cc
/*fdn*
            vod_sub no-label
            vod_cc no-label
*fdn*/            
            vod_project
            vod_entity
             base_damt 
             vod_desc
/*fdn*
            space(10)
            base_damt skip
            space(4)
            vod_desc
*fdn*/            
         with title color normal (getFrameTitle("DISTRIBUTION",19)) STREAM-IO /*GUI*/ .
         {&APVOIQB-P-TAG31}

      end.

      {&APVOIQB-P-TAG32}
      {&APVOIQB-P-TAG21}

      for each ckd_det where ckd_voucher = ap_ref no-lock,
            each ck_mstr where ck_ref = ckd_ref and ck_status <> "Void"
         no-lock with frame e width 120
            on endkey undo, return:

         /* SET EXTERNAL LABELS */
         setFrameLabels(frame e:handle).
         find apmstr where apmstr.ap_ref = ckd_ref
            and apmstr.ap_type = "CK"
         no-lock.
         {&APVOIQB-P-TAG22}
         assign
            base_camt = ckd_amt
            base_disc = ckd_disc
            disp_curr = "".
         {&APVOIQB-P-TAG14}
         if base_rpt = "" and apmstr.ap_curr <> base_curr
         then do:
            {&APVOIQB-P-TAG15}

            /* CONVERT FROM FOREIGN TO BASE CURRENCY */
            {gprunp.i "mcpl" "p" "mc-curr-conv"
               "(input ap_curr,
                 input base_curr,
                 input ap_ex_rate,
                 input ap_ex_rate2,
                 input base_camt,
                 input true, /* ROUND */
                 output base_camt,
                 output mc-error-number)"}.
            if mc-error-number <> 0 then do:
               {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
            end.

            /* CONVERT FROM FOREIGN TO BASE CURRENCY */
            {gprunp.i "mcpl" "p" "mc-curr-conv"
               "(input ap_curr,
                 input base_curr,
                 input ap_ex_rate,
                 input ap_ex_rate2,
                 input base_disc,
                 input true, /* ROUND */
                 output base_disc,
                 output mc-error-number)"}.
            if mc-error-number <> 0 then do:
               {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
            end.

            disp_curr = getTermLabel("YES",1).
         end.

         {&APVOIQB-P-TAG16}
         if et_report_curr <> mc-rpt-curr then do:
            {&APVOIQB-P-TAG17}
            {gprunp.i "mcpl" "p" "mc-curr-conv"
               "(input mc-rpt-curr,
                 input et_report_curr,
                 input et_rate1,
                 input et_rate2,
                 input base_camt,
                 input true,  /* ROUND */
                 output base_camt,
                 output mc-error-number)"}
            if mc-error-number <> 0 then do:
               {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
            end.
            {gprunp.i "mcpl" "p" "mc-curr-conv"
               "(input mc-rpt-curr,
                 input et_report_curr,
                 input et_rate1,
                 input et_rate2,
                 input base_disc,
                 input true,  /* ROUND */
                 output base_disc,
                 output mc-error-number)"}
            if mc-error-number <> 0 then do:
               {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
            end.
         end.  /* if et_report_curr <> mc-rpt-curr */

         {&APVOIQB-P-TAG18}
         {&APVOIQB-P-TAG33}
         display
            apmstr.ap_date
            ckd_ref format "x(8)"
            base_camt
            base_disc
            apmstr.ap_curr
            disp_curr no-label
         with title color normal (getFrameTitle("PAYMENTS",13)) STREAM-IO /*GUI*/ .
         {&APVOIQB-P-TAG34}
         {&APVOIQB-P-TAG19}
      end. /* FOR EACH CKD_DET */

      /* MULTIPLE POs */
      find vpo_det where vpo_ref = vo_ref no-lock no-error.
      if ambiguous vpo_det then do:
         for each vpo_det where vpo_ref = vo_ref no-lock
            with frame f centered no-labels
               title color normal
               (getFrameTitle("MULTIPLE_PO_NUMBERS",28)):
            /* SET EXTERNAL LABELS */
            setFrameLabels(frame f:handle).
            display vpo_po WITH STREAM-IO /*GUI*/ .
         end.
      end. /* IF AMBIGUOUS VPO_DET */

   end. /* IF NOT OPEN_ONLY ... */

   undo_all = no.

end. /* DO ON ENDKEY UNDO, RETURN */
